ABC248 D - Range Count Query
提出
code: python
from collections import defaultdict
n = int(input())
# 3 1 4 1 5
a = list(map(int, input().split()))
q = int(input())
# indexと数字の辞書
d = defaultdict(list)
for i, num in enumerate(a):
# print(d)
# defaultdict(<class 'list'>, {3: 1, 1: 2, 4, 4: 3, 5: 5}) for l, r, x in lrx:
ans = 0
for t in target:
if t >= l and t <= r:
ans += 1
print(ans)
解答
code: python
from collections import defaultdict
from bisect import bisect_left, bisect_right
n = int(input())
# 3 1 4 1 5
a = list(map(int, input().split()))
q = int(input())
# indexと数字の辞書
d = defaultdict(list)
for i, num in enumerate(a):
# print(d)
# defaultdict(<class 'list'>, {3: 1, 1: 2, 4, 4: 3, 5: 5}) for l, r, x in lrx:
print(bisect_right(target, r) - bisect_left(target, l))
テーマ
メモ
提出
code: python
from collections import defaultdict
import bisect
n = int(input())
a = list(map(int, input().split()))
q = int(input())
# 3 1 4 1 5
# 短調増加
d = defaultdict(list)
for i, v in enumerate(a):
for query in queries:
l, r, x = query
mi = bisect.bisect_left(t, l)
ma = bisect.bisect_right(t, r)
print(max(0, ma - mi))